 //app.js
import {} from './mpf/config/config.js';
import tokenManager from './mpf/auth/token-manager.js';
import appService from './api/AppService.js';
App({
  onLaunch:function(options){
    // 校验token是否失效,初始化配置
    if(tokenManager.get()){
      appService.init()
    }
    // 登录
    global.login = function () {
      var route = getCurrentPages();
      var options = route[route.length-1].options;
      var referer = '';
      var redirectTo =  ''
      for (var i in options) {
        referer = referer + i + '=' + options[i] + '&'
      }
      if (referer != '') {
        referer = '?' + referer.slice(0, -1)
      }
      if (route[route.length-1].route.indexOf('pages/login') == -1){
        var redirectTo = route[route.length - 1].route + referer
      }
      wx.navigateTo({
        url: '/pages/login/index?redirect=' + redirectTo,
      })
    }
    // webview
    global.webview = function (url) {
      wx.navigateTo({
        url: '/pages/webview/index?url=' + encodeURIComponent(url)
      })
    }
    // mta.Event.stat('yonghuxiadanzhu', { 'intostore': 'true' });//进入店铺
  },

  onError: function(msg){
    // global.onerror(msg);
  },
  globalData: {
    exit: false
  }
})